function selectRow(id)
{
	parent.frames["downFrame"].location = "roleByUser.action?userid="+id;
}
function addUser()
{
	window.open("/ItsOAsystem/system/user/newUser.jsp",'','width=350,height=250,left=500,top=400');
}
function submitAddUser()
{
	var username = document.getElementById("username").value;
	var password = document.getElementById("password").value;
	if(username!=null && username!="" && password !=null && password!="")
	{
		document.forms[0].submit();
		window.close();
	}else
	{
		alert("用户名和密码不能为空！");
		document.forms[0].action="";
	}	
}
function checkAll(checkbtn)
{
	var el = document.getElementsByTagName('input');
    var len = el.length;
    if(checkbtn.checked==true)
    {
    	for(var i=0; i<len; i++)
        {
            if(el[i].type=="checkbox")
            {
            	el[i].checked=true;
            }
        }
    	checkbtn.checked=true;
    }else
    {
    	for(var i=0; i<len; i++)
        {
            if(el[i].type=="checkbox")
            {
            	el[i].checked=false;
            }
        }
    	checkbtn.checked=false;
    }
}

function showDiv()
{
	var addWin = document.getElementById("addUserWin");
	addWin.style.visibility = "visible";
}
function closeDiv()
{
	var addWin = document.getElementById("addUserWin");
	addWin.style.visibility = "hidden";
}
/**
 * 切换详细信息栏
 * @param pageName
 * @return
 */
function turnTo(pageName)
{
	var userid = document.getElementById("userId").value;
	if(pageName=="userDetail")
	{
		parent.frames["downFrame"].location = "queryUserById.action?id="+userid;
	}else if(pageName=="roleAssign")
	{
		parent.frames["downFrame"].location = "roleByUser.action?userid="+userid;
	}
}
function delUserRole()
{
	var userid = document.getElementById("userId").value;
	var checkboxArray  = document.getElementsByTagName("input");
	var roleids = "";
	for(var i=0;i<checkboxArray.length;i++)
	{
		var check = checkboxArray[i];
		if(check.type=="checkbox"&&check.checked==true&&check.id=="check")
		{ 
			var roleid =check.value;
			roleids += roleids==""?roleid:","+roleid;
		}
	}
	if(roleids=="")
	{
		alert("请选择一个角色！");
		return;
	}
	parent.frames["downFrame"].location="delUserRole.action?userid="+userid+"&roleids="+roleids;
}
/**
 * 打开角色分配窗口
 * @return
 */
function openUserRoleWin()
{
	var userid = document.getElementById("userId").value;
	var url="rolesNotAssign.action?userid="+userid;
	window.showModalDialog(url, null, "dialogWidth =500px;dialogHeight =350px;status=no;resizable=no;" +
			"dialogLeft=350px;dialogTop=200px")
}
/**
 * 提交分配的角色
 * @return
 */
function submitAssign()
{
	var userid = document.getElementById("userId").value;
	var checkboxArray  = document.getElementsByTagName("input");
	var roleids = "";
	for(var i=0;i<checkboxArray.length;i++)
	{
		var check = checkboxArray[i];
		if(check.type=="checkbox"&&check.checked==true&&check.id=="check")
		{ 
			var roleid =check.value;
			roleids += roleids==""?roleid:","+roleid;
		}
	}
	if(roleids=="")
	{
		alert("请选择一个角色！");
		return;
	}
	opener.location = "addUserRole.action?userid="+userid+"&roleids="+roleids;
	window.close();
}